package contents

import (
	"github.com/pkg/errors"
	basicobject "yizhuoyan/go-study/pdfgo/raw/objects/basicobject"
	"yizhuoyan/go-study/pdfgo/raw/objects/indirectobject"
)

var catalogTypeValueString = "/Catalog"

type DocumentCatalog struct {
	*basicobject.Dictionary
	indirectobject.Locator
	Pages             *basicobject.IndirectObjectReference `validate:"required" #:""`
	PageLabels        *basicobject.IndirectObjectReference `validate:"omitempty" #:""`
	Names             *basicobject.Dictionary              `validate:"omitempty" #:""`
	Dests             *basicobject.Dictionary              `validate:"omitempty" #:""`
	Version           string                               `validate:"omitempty"`
	ViewerPreferences *basicobject.Dictionary              `validate:"omitempty" #:""`
	Outlines          *basicobject.IndirectObjectReference `validate:"omitempty" #:""`
	Threads           *basicobject.IndirectObjectReference `validate:"omitempty" #:""`
	OpenAction        *basicobject.DictionaryOrArray       `validate:"omitempty" #:""`
	AA                *basicobject.Dictionary              `validate:"omitempty" #:""`
	URI               *basicobject.Dictionary              `validate:"omitempty" #:""`
	AcroForm          *basicobject.Dictionary              `validate:"omitempty" #:""`
	Metadata          *basicobject.Dictionary              `validate:"omitempty" #:""`
	StructTreeRoot    *basicobject.Dictionary              `validate:"omitempty" #:""`
	MarkInfo          *basicobject.Dictionary              `validate:"omitempty" #:""`
	Lang              *basicobject.Dictionary              `validate:"omitempty" #:""`
	PageLayout        *basicobject.Name                    `validate:"omitempty" #:""`
	PageMode          *basicobject.Name                    `validate:"omitempty" #:""`
}

func (this *DocumentCatalog) ParseFrom(dic *basicobject.Dictionary, indirectObjectLocator indirectobject.Locator) error {
	if !dic.HasKeyAndNameValue("/Type", catalogTypeValueString) {
		return errors.Errorf("非%s /Type", catalogTypeValueString)
	}
	if !dic.HasKey("/Pages") {
		return errors.New("必须包含/Pages")
	}
	this.Pages = dic.MustGetIndirectObjectReference("/Pages")
	this.Locator = indirectObjectLocator
	return nil
}
